﻿@model OJS.Web.Areas.Administration.ViewModels.Submission.SubmissionAdministrationViewModel

@Html.HiddenFor(model => model.Id)

<style>
    #FileUploadSubmissionContainer {
        display: none;
    }
    #CodeSubmissionContainer {
        display: none;
    }
</style>

@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.AllowBinaryFilesUpload)

<div class="form-group">
    @Html.LabelFor(model => model.ProblemId, new { @class = "control-label col-md-12" })
    <div class="col-md-12">
        @Html.EditorFor(model => model.ProblemId)
        @Html.ValidationMessageFor(model => model.ProblemId)
    </div>
</div>

<div class="form-group">
    @Html.LabelFor(model => model.ParticipantId, new { @class = "control-label col-md-12" })
    <div class="col-md-12">
        @Html.EditorFor(model => model.ParticipantId)
        @Html.ValidationMessageFor(model => model.ParticipantId)
    </div>
</div>

<div class="form-group">
    @Html.LabelFor(model => model.SubmissionTypeId, new { @class = "control-label col-md-12" })
    <div class="col-md-12">
        @Html.EditorFor(model => model.SubmissionTypeId, new { Model.AllowBinaryFilesUpload })
        @Html.ValidationMessageFor(model => model.SubmissionTypeId)
    </div>
</div>

<div id="FileUploadSubmissionContainer" class="form-group">
    @if (Model.Content != null)
    {
        @Html.LabelFor(model => model.FileSubmission, new { @class = "control-label col-md-12" })
        <div class="col-md-12">
            @Html.ActionLink("Свали решението", "GetSubmissionFile", "Submissions", new { area = "Administration", submissionId = Model.Id }, null)
        </div>
    }
        
    @Html.Label("Качи ново решение", new { @class = "control-label col-md-12" })
    <div class="col-md-12">
        @(Html.Kendo().Upload()
            .Name("FileSubmission")
            .Multiple(false)
            .ShowFileList(true)
            .Messages(message => message.Select("Избери файл.."))
            .HtmlAttributes(new { id = "FileSubmission" }))
        @Html.ValidationMessageFor(model => model.Content)
    </div>
    @Html.Label("Разрешени файлови формати: ", new { @class = "control-label col-md-12" })
    <div id="AllowedFileExtensionsBox" class="col-md-12">

    </div>
</div>

<div id="CodeSubmissionContainer" class="form-group">
    @Html.LabelFor(model => model.ContentAsString, new { @class = "control-label col-md-12" })
    <div class="col-md-12">
        @Html.EditorFor(model => model.ContentAsString)
        @Html.ValidationMessageFor(model => model.Content)
    </div>
</div>

<script>
    function onSubmissionDataBound(e) {
        return changeSubmissionType(e, this);
    }

    function onSubmissionTypeChange(e) {
        return changeSubmissionType(e, this);
    }

    function changeSubmissionType(e, thisObjectFromEvent) {
        var index = thisObjectFromEvent.selectedIndex;
        var dataItem = thisObjectFromEvent.dataItem(index);
        var form = $("#SubmissionForm");
        var fileUpload = $("#FileUploadSubmissionContainer");
        var codeArea = $("#CodeSubmissionContainer");
        var formAction = form.attr("action");

        debugger;
        if (dataItem.AllowBinaryFilesUpload === true) {
            form.attr("data-ajax", "false");
            fileUpload.show();
            codeArea.hide();
            $("#AllowedFileExtensionsBox").html(dataItem.AllowedFileExtensions);
        } else if (dataItem.AllowBinaryFilesUpload === false) {
            fileUpload.hide();
            codeArea.show();
        }
        else
        {
            fileUpload.hide();
            codeArea.hide();
        }
    }
</script>